﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Shipwire.Tests
{
    [TestClass]
    public class TrackingTests
    {
        [TestMethod]
        public void CheckGetAllReturnsMany()
        {
            IShipwireService service = TestShipwireAccount.CreateSandboxService();
            var response = service.GetAllTrackingData();

            Assert.AreEqual("0", response.Status);
            Assert.IsNull(response.ErrorMessage);

            Assert.IsNotNull(response.Orders);
            Assert.IsTrue(response.Orders.Length > 0);
        }

        [TestMethod]
        public void TestSpecificCustomerOrder()
        {
            string customerOrderId = "TEST1";

            IShipwireService service = TestShipwireAccount.CreateSandboxService();
            var response = service.TrackCustomerOrder(customerOrderId);

            Assert.AreEqual("0", response.Status);
            Assert.IsNull(response.ErrorMessage);

            Assert.IsNotNull(response.Orders);
            Assert.AreEqual(1, response.Orders.Length);

            var order = response.Orders[0];
            Assert.AreEqual(customerOrderId, order.Id);

            
            Assert.AreEqual(DateTime.Parse("15/03/2012"), order.ExpectedDeliveryDate);

            Assert.AreEqual(0, order.Handling);
            Assert.AreEqual(0, order.Insurance);
            Assert.AreEqual(0, order.Packaging);
            Assert.AreEqual(2.69M, order.Shipping);
            Assert.AreEqual(2.69M, order.Total);

            Assert.AreEqual("https://app.shipwire.com/c/t/30f4c4e3936eda6de220171fa39af6b4:11679053", order.Link);
            Assert.AreEqual("YES", order.ManuallyEdited);

            Assert.AreEqual("NO", order.Returned);
            Assert.IsNull(order.ReturnDate);

            Assert.AreEqual(DateTime.Parse("13/03/2012 13:02:59"), order.ShipDate);
            Assert.AreEqual("YES", order.Shipped);

            Assert.AreEqual("RM FCLR", order.Shipper);
            Assert.AreEqual("Royal Mail First Class Large Letter - Recorded Signed For", order.ShipperFullName);

            Assert.IsNotNull(order.TrackingNumber);
            Assert.AreEqual("AU119436665GB", order.TrackingNumber.Value);
            Assert.AreEqual("http://www.royalmail.com/portal/rm/track?trackNumber=AU119436665GB", order.TrackingNumber.Link);
            Assert.AreEqual("RM", order.TrackingNumber.Carrier);
        }
    }
}
